package com.zmx.promote.web;

import com.zmx.common.common.web.AbstractController;
import com.zmx.common.common.web.rest.ResponseResult;
import com.zmx.dto.PromoteActiveDto;
import com.zmx.promote.service.PromoteActiveService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description PromoteActiveController
 * @Author mengzhiming
 * @Email hijrming@163.com
 * @Date 2022/1/7
 **/
@Slf4j
@RestController
@RequestMapping("/active")
public class PromoteActiveController extends AbstractController<PromoteActiveDto, PromoteActiveService> {

    @Autowired
    private PromoteActiveService activeService;

    @ApiOperation(value = "分页获取活动列表", tags = "分页获取活动列表")
    @GetMapping("getActivePage")
    public Object getActivePage(@RequestParam("pageIndex") Integer pageIndex,
                                @RequestParam("pageSize") Integer pageSize) {
        try {
            Page<PromoteActiveDto> page = activeService.getActivePage(pageIndex, pageSize);
            return ResponseResult.success(page);
        } catch (Exception e) {
            log.error("分页查询活动列表失败！", e);
            return ResponseResult.fail("分页查询活动列表失败");
        }
    }

    @ApiOperation(value = "根据活动类型查询活动", tags = "根据活动类型查询活动")
    @GetMapping("getSkillActiveList")
    public Object getSkillActiveList(@RequestParam("type") Integer type) {
        log.info("begin to getSkillActiveList  type: {}", type);
        try {
            List<PromoteActiveDto> activeDTOList = activeService.getSkillActiveList(type);
            return ResponseResult.success(activeDTOList);
        } catch (Exception e) {
            log.error("分页查询活动列表失败！", e);
            return ResponseResult.fail("分页查询活动列表失败");
        }
    }
}
